﻿<%
Class C_Page
	Private rs
	Public page
	Public page_size
	Public page_count
	Public record_count
	
	Private start_p
	Private end_p
	
	Private Sub Class_Initialize()
		
		'获取本页编号
		page = request.QueryString("page")
		if page = "" then
			page = 1
		else
			page = cint(page)
		end if
		
		'设置一页默认显示数量
		page_size = 10

	End Sub
	
	'URL过滤
	Private Function FilterURL(s)
		dim i,arr,href
		arr = split(s,"&")
		href = ""
		for i = 0 to ubound(arr)
			if not left(arr(i),4) = "page" then
				if href = "" then
					href = arr(i)
				else
					href = href & "&" & arr(i)
				end if
			end if
		next
		FilterURL = href
	End Function
	
	'设置RS
	Public Function setRS(r)
		set rs = r
		rs.pagesize = page_size
		rs.absolutepage = page
		
		'设置内容总数
		record_count = rs.recordcount
		page_count = rs.pagecount
		
		'设置页数列表
		if page_count <= page_size then
			start_p = 1
			end_p = page_count
		else
			if (page + 4) <= page_count then
				if (page - 4) < 1 then
					start_p = 1
					end_p = 9
				else
					start_p = page - 4
					end_p = page + 4
				end if
			else
				start_p = page - (page + 4 - page_count) - 4
				end_p = page_count
			end if
		end if
	End Function
	
	'显示分页
	Public Function page_list()
		dim url
		url = FilterURL(request.QueryString)
		
		if start_p <> 1 then
			response.Write("<a href='?page=1&"& url &"'>1...</a>")
		end if
		for i = start_p to end_p
			if i = page then
				response.Write("<span>"& i &"</span>")
			else
				response.Write("<a href='?page="& i &"&"& url &"'>"& i &"</a>")
			end if
		next
		if end_p <> page_count then
			response.Write("<a href='?page="& page_count &"&"& url &"'>..."& page_count &"</a>")
		end if
	End Function
End Class
%>
